<template>
  <el-dialog title="字典结果" v-model="dialogVisible">
    <el-row>
      <el-col :span="24">
        <el-table border :data="tableData" style="width: 100%">
          <el-table-column label="释义" prop="label" />
          <el-table-column label="码值" prop="value" />
        </el-table>
      </el-col>
    </el-row>
    <el-row class="mt-5">
      <el-pagination
        v-model:current-page="searchForm.current"
        v-model:page-size="searchForm.size"
        layout="total,sizes,prev, pager, next,jumper"
        :page-sizes="[10, 50, 100, 200, 500]"
        :total="total"
        @size-change="handleSizeChange"
        :background="true"
        @current-change="handleCurrentChange"
      />
    </el-row>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
import { getDictByCode } from "@/api/modules/dict";
const dialogVisible = ref(false);
const tableData = ref([]);
const openDialog = dictCode => {
  if (dictCode) {
    searchForm.value.dictCode = dictCode;
    tableData.value = [];
    //获取角色列表
    search();
  }
};
const searchForm = ref({
  current: 1,
  size: 10,
  dictCode: ""
});
const search = () => {
  getDictByCode(searchForm.value)
    .then(res => {
      if (res.code === 200) {
        dialogVisible.value = true;
        tableData.value = res.data.others;
        total.value = res.data.total;
      } else {
        dialogVisible.value = false;
      }
    })
    .catch(() => {
      dialogVisible.value = false;
    });
};
const total = ref(0);
const handleSizeChange = val => {
  searchForm.value.size = val;
  search();
};
const handleCurrentChange = val => {
  searchForm.value.current = val;
  search();
};
defineExpose({
  openDialog
});
</script>
